<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise 模式显示城市信息</title>
</head>
<script src="./jquery.js"></script>
<body>
    
</body>
<script>
    function request(option){
        var def = $.Deferred();
        if(!option || !option.url){
            throw Error('url is undefined');
        }
        var _config = {
            url: option.url,
            type:'get',
            dataType:'JSON',
            success: function(res){
                def.resolve(res);
            },
            error:function(a,b,err){
                def.reject(err);
            }
        }
        // $.extend(_config,option,true);
        $.ajax(_config);
        return def.promise();
    }

    var option = {
        url: './city.json'
    }

    request(option).then(function(data){
        console.log(data);
    }, function(err){
        console.log(err);
    })
</script>
</html>